const mongoose=require("mongoose");
mongoose.connect("mongodb://localhost/test");
mongoose.Promise=Promise;

const Schema=mongoose.Schema({
  name:String,
  age:Number
});

const User=mongoose.model('User',Schema);


 async function run(){
       await User.remove();
       //创建多个数据对象
       await User.create([
         {name:"kaka",age:13},
         {name:"kaka",age:15},
         {name:"xixi",age:17},
         {name:"xixi",age:19}
       ]);
       //利用find查找对应的数据对象
      const list=await User.find({name:"kaka"});
      const num=await User.count({name:"xixi"});
      await User.findOneAndUpdate({name:"xixi"},{age:1999});
      const u=await User.findOne({name:"xixi"});
          console.log(num);
          console.log(list);
          console.log(u);
      await User.findOneAndRemove({name:"xixi"});
      console.log(await User.findOne({age:1999}));
 }

 run();
